'use strict'

/**
 * @description 后台 - 用户列表 - 订单节点 apis
 * @fileName order-node-apis.js
 * @date 2025/10/08 21:22:16
 */

const APILIST = (function ($, global) {
  const layer = global.layer

  const request = function (options) {
    return $.ajax({
      type: 'POST',
      dataType: 'json',
      ...options,
    })
  }

  return {
    parentConf: null,
    userConf: null,

    // 获取用可用的 `use_extends` 字段
    getBaseInfo: function (callback) {
      const that = this
      const URL = '/app/admin/v1-api/getUserExtend?type=2'
      $.ajax({
        url: URL,
        type: 'get',
        success: function (res) {
          if (res.code) {
            layer.closeAll('loading')
            return layer.msg(res.msg)
          }
          const { parent_user_extend, user_extend } = res.data
          that.parentConf = parent_user_extend
          that.userConf = user_extend
          callback && callback(user_extend)
        },
      })
    },

    // 续费时间列表
    getNodeRenewDurationList(opts, callback) {
      request({
        url: `/app/admin/v1-api/getNodeRenewDurationList?line_id=${opts.line_id}&user_id=${opts.user_id}`,
        data: opts,
        success(res) {
          if (res.code) {
            layer.closeAll('loading')
            return layer.msg(res.msg)
          }
          callback && callback(res.data)
        },
      })
    },

    // 执行续费 - 执行续费时间
    postRenewDuration(data, callback) {
      request({
        url: '/app/admin/v1-api/renew',
        data,
        success(res) {
          if (res.code) {
            layer.closeAll('loading')
            return layer.msg(res.msg)
          }
          callback && callback(res)
        },
      })
    },

    // 搜索下级会员列表
    getInvitationUserListURL: '/app/admin/v1-api/getInvitationUserList',

    // 过户
    setTransferUser(data, callback) {
      request({
        url: '/app/admin/v1-api/transfer',
        data,
        success(res) {
          if (res.code) {
            layer.closeAll('loading')
            return layer.msg(res.msg)
          }
          callback && callback(res)
        },
      })
    },

    // 获取平均时间列表(文档)
    getAverageTimeList(callback) {
      request({
        url: '/app/admin/v1-api/getAverageTimeList',
        data: {},
        success(res) {
          if (res.code) {
            layer.closeAll('loading')
            return layer.msg(res.msg)
          }
          callback && callback(res.data)
        },
      })
    },

    // 平均时间
    setAverageTime(data, callback) {
      request({
        url: '/app/admin/v1-api/averageTime',
        data,
        success(res) {
          if (res.code) {
            layer.closeAll('loading')
            return layer.msg(res.msg)
          }
          callback && callback(res)
        },
      })
    },

    // 修改密码
    putUserUpdatePwd(data, callback) {
      request({
        url: '/app/admin/v1-api/updatePwd',
        data,
        success(res) {
          if (res.code) {
            layer.closeAll('loading')
            return layer.msg(res.msg)
          }
          callback && callback(res)
        },
      })
    },

    // 调换-自定义账号列表
    getCustomAccountList(callback) {
      request({
        url: '/app/admin/v1-api/getCustomTypeListExchange',
        data: {},
        success(res) {
          if (res.code) {
            layer.closeAll('loading')
            return layer.msg(res.msg)
          }
          callback && callback(res.data)
        },
      })
    },

    // 调换
    putExchange(data, callback) {
      request({
        url: '/app/admin/v1-api/exchange',
        data,
        success(res) {
          if (res.code) {
            layer.closeAll('loading')
            return layer.msg(res.msg)
          }
          callback && callback(res)
        },
      })
    },

    // 获取线路列表
    getLines(data, callback) {
      request({
        url: '/app/admin/v1-api/getLineIds',
        data,
        success(res) {
          if (res.code) {
            layer.closeAll('loading')
            return layer.msg(res.msg)
          }
          callback && callback(res.data)
        },
      })
    },
  }
})(layui.$, layui)
